#include <nds.h>
#include "graphics_font.h"

void GlyphTable::addCP(u32 codepoint)
{
	bool found = false;
	for (u16 i=0; i<glyphs.size(); ++i)
	{
		if (glyphs[i].codepoint == codepoint) 
		{
			found = true;
			break;
		}
	}
	
	if (!found)
	{
		glyph tmp;
		tmp.codepoint = codepoint;
		glyphs.push_back( tmp );
	}
}

void GlyphTable::sort()
{
	bool sorted = false;
	glyph temp;
	
	while (!sorted)
	{
		sorted = true;
		for (u16 i=1; i < glyphs.size(); ++i)
		{
			if ( glyphs[i-1].codepoint > glyphs[i].codepoint )
			{
				temp = glyphs[i-1];
				glyphs[i-1] = glyphs[i];
				glyphs[i] = temp;
				sorted = false;
			}
		}
	}
}

std::string GlyphTable::getGlyphHex(u32 codepoint)
{
	std::string nullglyph = "00000000000000000000000000000000";
	
	for (u16 i=0; i < glyphs.size(); ++i)
	{
		if ( glyphs[i].codepoint == codepoint )
		{
			return glyphs[i].data;
		}
	}
	return nullglyph;
}
